package org.example.movies.controller;

import com.alibaba.fastjson.JSONObject;
import org.example.movies.service.DetailService;

import org.example.movies.service.impl.DetailServiceImpl;
import org.example.movies.utils.IndexData;
import org.example.movies.utils.ResponseEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ClassifyController")
public class ClassifyController extends HttpServlet {
    private DetailService service = new DetailServiceImpl();
    public static final String CONTENT_TYPE_JSON = "application/json; charset=utf-8";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResponseEntity responseEntity = new ResponseEntity();
        String id = req.getParameter("id");
        IndexData films = service.getClassify(id);
        responseEntity.setData(films);
        responseEntity.setStatus(200);
        responseEntity.setMsg("success");
        resp.setContentType(CONTENT_TYPE_JSON);
        resp.getWriter().println(JSONObject.toJSONString(responseEntity));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
